package com.yiquan.user.dao.db;

import com.yiquan.user.pojo.UserActivity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Tyrone
 * @date 2021/12/31 1:09
 */
public interface UserActivityDao extends JpaRepository<UserActivity, Long>, JpaSpecificationExecutor<UserActivity> {

    @Query(nativeQuery = true, value = "select  * from yiquan_user_activity where  from_user_id = ?1 and to_user_id = ?2")
    UserActivity findByFromUserIdAndToUserId(Long fromUserId, Long toUserId);

    @Query(nativeQuery = true, value = "delete from yiquan_user_activity where  from_user_id = ?1 and to_user_id = ?2")
    @Modifying
    @Transactional
    int deleteByFromUserIdAndToUserId(Long fromUserId, Long toUserId);

    @Query (nativeQuery = true,value = "update yiquan_user_activity set status = ?2 where to_user_id = ?1")
    @Modifying
    @Transactional
    void updateVideoActivityStatus(Long userId, Integer status);

//    Integer countUserActivitiesByFrom_user_id(Long userId);
//
//    Integer countUserActivitiesByTo_user_id(Long toUserId);

    @Query(nativeQuery = true,value = "select  * from yiquan_user_activity where to_user_id = ?1 and activity = ?2 and status = ?3")
    List<UserActivity> getActivity(Long toUserId, Integer activity, Integer status);
}
